﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace NinjaToolbox.PhysicsSystem
{
    public class ColliderObject : MonoBehaviour
    {
        [SerializeField]
        OBBBox mColliderShape = new OBBBox() { size = Vector3.one, gizmosColor = Color.Lerp(Color.green, Color.white, 0.6f) };
        public bool alwaysVisibleGizmos = true;
        public bool isDrawGizmos = true;

        public OBBBox ColliderShape { get { mColliderShape.matrix = transform.localToWorldMatrix; return mColliderShape; } }


        public void SetColliderShape(OBBBox obbBox)
        {
            mColliderShape = obbBox;
        }

        void OnEnable()
        {
            PhysicsSystemManager.Instance.RegistColliderObject(this);
        }

        void OnDisable()
        {
            if (PhysicsSystemManager.Instance != null)
                PhysicsSystemManager.Instance.UnregistColliderObject(this);
        }

        void OnDrawGizmos()
        {
            if (!alwaysVisibleGizmos) return;

            DrawGizmos();
        }

        void OnDrawGizmosSelected()
        {
            if (alwaysVisibleGizmos) return;

            DrawGizmos();
        }

        void DrawGizmos()
        {
            if (!isDrawGizmos) return;

            DrawShapeGizmos();
        }

        void DrawShapeGizmos()
        {
            ColliderShape.DrawGizmos();
        }
    }
}
